package com.neusoft.lohas.common.pay.payutil.unionpay.examples;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.neusoft.lohas.common.pay.payutil.unionpay.conf.SklConfig;
import com.neusoft.lohas.common.pay.payutil.unionpay.service.SklService;

/**
 * Created with IntelliJ IDEA.
 * User: HS-AVA
 * Date: 14-1-8
 * Time: 上午9:48
 * To change this template use File | Settings | File Templates.
 */
public class QueryExample {
	public static void main(String[] args) {
		// 请求要素
		Map<String, String> req = new HashMap<String, String>();
		req.put("tradetype", "03"); // 报文类型
		req.put("mercode", SklConfig.MER_ID); // 商户号
		req.put("orderno", generateOrdrNo()); // 订单号

		Map<String, String> resp = new HashMap<String, String>();
		boolean validResp = SklService.query(req, resp);

		// 商户的业务逻辑
		if (validResp) {
			// 服务器应答签名验证成功
			System.out.println("成功");
		} else {
			// 服务器应答签名验证失败
			System.out.println("失败");
		}
	}

	/**
	 * 订单号生成，该生产订单号仅用于测试，商户根据自己需要生成订单号
	 * @return
	 */
	public static String generateOrdrNo() {
		DateFormat formater = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		StringBuilder sb = new StringBuilder(formater.format(new Date()));
		return sb.toString();
	}
}
